package org.jeecg.modules.bicycle.order.controller;

import java.util.Arrays;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.bicycle.order.entity.BikeVehicleOrder;
import org.jeecg.modules.bicycle.order.service.IBikeVehicleOrderService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.bicycle.order.vo.BikeVehicleOrderByIdRes;
import org.jeecg.modules.bicycle.order.vo.BikeVehicleOrderRes;
import org.jeecg.modules.bicycle.order.vo.IsFree;
import org.jeecg.modules.bicycle.order.vo.Refund;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: 借车记录
 * @Author: 月月鸟
 * @Date:   2021-05-28
 * @Version: V1.0
 */
@Api(tags="借车记录")
@RestController
@RequestMapping("/order/bikeVehicleOrder")
@Slf4j
public class BikeVehicleOrderController extends JeecgController<BikeVehicleOrder, IBikeVehicleOrderService> {
	@Autowired
	private IBikeVehicleOrderService bikeVehicleOrderService;

	 /**
	  * 分页列表查询
	  *
	  * @param bikeVehicleOrderRes
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 @ApiOperation(value="借车记录-分页拼接列表查询", notes="借车记录-分页拼接列表查询")
	 @GetMapping(value = "/pageList")
	 public Result<?> pageList(BikeVehicleOrderRes bikeVehicleOrderRes,
							   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
							   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
							   HttpServletRequest req) {

		 return bikeVehicleOrderService.pageList(pageNo,pageSize,bikeVehicleOrderRes);
	 }

	 @ApiOperation(value="借车记录-查看接口", notes="借车记录-查看接口")
	 @GetMapping(value = "/pageListById")
	 public Result<?> pageList(@RequestParam String id, HttpServletRequest req,BikeVehicleOrderByIdRes bikeVehicleOrderByIdRes) {

		 return bikeVehicleOrderService.pageListById(id);
	 }
	/**
	  *   添加
	  *
	  * @param bikeVehicleOrder
	  * @return
	  */
	 @AutoLog(value = "借车记录-添加")
	 @ApiOperation(value="借车记录-添加", notes="借车记录-添加")
	 @PostMapping(value = "/add")
	 public Result<?> add(@RequestBody BikeVehicleOrder bikeVehicleOrder) {
		 bikeVehicleOrderService.save(bikeVehicleOrder);
		 return Result.OK("添加成功！");
	 }

	 /**
	  *
	  *
	  * @param isFree
	  * @return
	  */
	 @AutoLog(value = "借车记录-退款",operateType = 3)
	 @ApiOperation(value="借车记录-退款", notes="借车记录-退款")
	 @PutMapping(value = "/refund")
	 public Result<?> refund(@RequestBody IsFree isFree) {
		 return bikeVehicleOrderService.isRefund(isFree);
	 }
	/**
	 *  编辑
	 *
	 * @param bikeVehicleOrder
	 * @return
	 */
	@AutoLog(value = "借车记录-编辑",operateType = 3)
	@ApiOperation(value="借车记录-编辑", notes="借车记录-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody BikeVehicleOrder bikeVehicleOrder) {
		bikeVehicleOrderService.updateById(bikeVehicleOrder);
		return Result.OK("编辑成功!");
	}

	 /**
	  * 免单 免费 费用
	  * */
	 @AutoLog(value = "借车记录-免单",operateType = 3)
	 @ApiOperation(value = "免单",notes = "免单")
	 @PutMapping(value = "/isFree")
	 public Result<?> isFree(@RequestBody IsFree isFree){
		 return bikeVehicleOrderService.isFree(isFree);
	 }
	 /**
	  * 借车记录-后台还车
	  * @param id
	  * */
	 @AutoLog(value = "借车记录-后台还车")
	 @ApiOperation(value = "借车记录-后台还车",notes = "借车记录-后台还车")
	 @DeleteMapping(value = "/stopTimeCost")
	 public Result<?> stopTimeCost(@RequestParam String id){
		 return bikeVehicleOrderService.stopTimeCost(id);
	 }
	 /**
	  * 借车记录-停止计费
	  *  @param bikeVehicleOrderRes
	  * */
	 @AutoLog(value = "借车记录-停止计费",operateType = 3)
	 @ApiOperation(value = "停止计费",notes = "停止计费")
	 @PutMapping (value = "/stopTime")
	 public Result<?> stopTime(@RequestBody BikeVehicleOrderRes bikeVehicleOrderRes){
		 return bikeVehicleOrderService.stopTime(bikeVehicleOrderRes);
	 }
	 /**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "借车记录-通过id删除")
	@ApiOperation(value="借车记录-通过id删除", notes="借车记录-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		bikeVehicleOrderService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "借车记录-批量删除")
	@ApiOperation(value="借车记录-批量删除", notes="借车记录-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.bikeVehicleOrderService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="借车记录-通过id查询", notes="借车记录-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		BikeVehicleOrder bikeVehicleOrder = bikeVehicleOrderService.getById(id);
		if(bikeVehicleOrder==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(bikeVehicleOrder);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param bikeVehicleOrderRes
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, BikeVehicleOrderRes bikeVehicleOrderRes) {
        return bikeVehicleOrderService.exportXls(request,bikeVehicleOrderRes);
    }

}
